package de.stefanocke.roo.xtend;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue;
import org.springframework.roo.classpath.details.annotations.AnnotationMetadata;
import org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder;
import org.springframework.roo.model.JavaType;

public class Annotation {
	private Annotation() {

	}

	public static AnnotationMetadataBuilder annotation(JavaType type) {
		return new AnnotationMetadataBuilder(type);
	}

	public static AnnotationMetadataBuilder annotation(String fqn) {
		return new AnnotationMetadataBuilder(new JavaType(fqn));
	}

	public static AnnotationMetadataBuilder annotation(String fqn, AnnotationAttributeValue<?>... attributes) {
		return new AnnotationMetadataBuilder(new JavaType(fqn), Arrays.asList(attributes));
	}
	
	public static boolean hasType(AnnotationMetadataBuilder amb, String typeFqn){
		return hasType(amb, new JavaType(typeFqn));
	}
	public static boolean hasType(AnnotationMetadataBuilder amb, JavaType type){
		return type.equals(amb.getAnnotationType());
	}

	public static List<AnnotationMetadataBuilder> annotationsToBuilders(List<AnnotationMetadata> annotations) {
		List<AnnotationMetadataBuilder> builders = new ArrayList<AnnotationMetadataBuilder>();
		for (AnnotationMetadata annotationMetadata : annotations) {
			builders.add(new AnnotationMetadataBuilder(annotationMetadata));
		}
		return builders;

	}

	public static List<AnnotationMetadataBuilder> operator_plus(AnnotationMetadataBuilder b1,
			AnnotationMetadataBuilder b2) {
		List<AnnotationMetadataBuilder> list = new ArrayList<AnnotationMetadataBuilder>();
		list.add(b1);
		list.add(b2);
		return list;
	}

}
